package com.wnx.db;

import java.util.List;

import org.hibernate.Session;
import org.hibernate.Transaction;
import org.hibernate.query.Query;

import com.wnx.entity.Menu;
import com.wnx.entity.Review;
import com.wnx.util.HibernateUtil;

public class ReviewDao {

	public ReviewDao(){
		
	}
	public Review saveReview(Review r){
		Session session = new HibernateUtil().getSession();
		 Transaction transaction = session.beginTransaction();
		 session.save(r);
		 transaction.commit();
		 session.close();
		return r;
		
	}
	public List getReviewFive(int gid){
		Session session = HibernateUtil.getSession();
		session.beginTransaction();
		String hql = "from Review where gid=?";
		Query<Review> query = session.createQuery(hql,Review.class);
		query.setParameter(0, gid);
		query.setFirstResult(0).setMaxResults(5);
		List list=query.list();
		session.getTransaction().commit();
		session.close();
		return list;
	}
	public List getReviewAll(int gid){
		Session session = HibernateUtil.getSession();
		session.beginTransaction();
		String hql = "from Review where gid=?";
		Query<Review> query = session.createQuery(hql,Review.class);
		query.setParameter(0, gid);
		List list=query.list();
		session.getTransaction().commit();
		session.close();
		return list;
	}
}
